package com.ybkj.o2o.zhuanche.amqp.rabbitTemplate;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.io.Serializable;
import java.util.concurrent.TimeoutException;

/**
 * 
 * @author jacklee
 *
 */
@Component
@Scope("prototype")
public class PushTemplate extends BaseTemplate {

	
	/**
	 * 构造方法初始化rabbit配置
	 * @throws TimeoutException 
	 * @throws IOException 
	 */
	public PushTemplate() throws IOException, TimeoutException {
		super();
	}
	
	/**
	 * 发送消息到队列服务器
	 * object  发送的消息对象（需要强转Serializable类型）
	 * 
	 */
	public void sendMessage(Serializable object)  {
	    try {

	    	JSONObject jo = (JSONObject) JSON.toJSON(object);
	    	
			channel.basicPublish(EXCHANGR_NAME,"", null, jo.toString().getBytes("utf-8"));
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
